package taller2.controller.MainEdittingMenu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.ChangeableWindow;
import taller2.interfaces.Graph;
import taller2.interfaces.MenuConBotones;
import taller2.view.draws.DrawingArea;
import taller2.view.windows.CreatorWindows.GraphCreatorWindow;

public class AreaMenuListener implements ActionListener,ChangeListener{
	protected DrawingArea area;
	protected Graph graph;
	protected MenuConBotones menu;
	protected AlgorithmApplicator algorithmApplicator;
	protected ChangeableWindow window;
	// constructor
	public AreaMenuListener(ChangeableWindow window, DrawingArea area, Graph graph,MenuConBotones menu, AlgorithmApplicator algorithmApplicator) {
		this.area = area;
		this.graph = graph;
		this.menu = menu;
		this.algorithmApplicator = algorithmApplicator;
		this.window = window;
	}
	
	// launches the graphCreator window popup
	public void actionPerformed(ActionEvent event) {
		new GraphCreatorWindow(window, graph, area, algorithmApplicator);
		menu.unselectButtons();
	}
	
	// detects when user changes the size of the bar
	public void stateChanged(ChangeEvent e) {
		int tam = ((JSlider)e.getSource()).getValue();	
		area.resizeGraph(tam,tam/10 - 1,(float)(2*tam)/100);
	}
}
